<template>
  <div>
    <div class="news-title flex-a flex-b">
      <div class="flex-a">
        <span>秒杀特价</span>
        <nut-countdown v-model="time" :end-time="endTime">
          <nut-space>
            <div class="countdown-item">{{ time.h }}</div>
            <div style="color: #FF7F31;margin-top: 10rpx;">:</div>
            <div class="countdown-item">{{ time.m }}</div>
            <div style="color: #FF7F31;margin-top: 10rpx;">:</div>
            <div class="countdown-item">{{ time.s }}</div>
          </nut-space>
        </nut-countdown>
      </div>
      <div class="more" @click="jumpTo('/packageA/pages/hot/index')">更多</div>
    </div>
    <div class="goods-list">
      <div class="goods-item" v-for="item in state.goodsList" :key="item.goodsId"
        @click="jumpTo('/packageA/pages/productDetail/index?goodsId=' + item.goodsId)">
        <div class="img"><img :src="item.goodsCoverImg" mode="aspectFit" alt=""></div>
        <div class="title">{{ item.goodsName }}</div>
        <!-- <div class="time"><nut-countdown :end-time="state.end" /></div> -->
        <div class="bottom flex-a">
          <span class="sell"><text>折后</text>￥{{ item.sellingPrice }}</span>
          <span class="orig">￥{{ item.originalPrice }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import Taro from '@tarojs/taro'
import { reactive, onMounted, ref } from 'vue';
import { getNewGoods } from '../../../api/index'
export default {
  setup() {
    const endTime = ref(0) as any
    const time = ref({
      h: '00',
      m: '00',
      s: '00'
    })
    const state = reactive({
      goodsList: [],
      end: Date.now() + 30 * 60 * 1000,
    });
    onMounted(() => {
      const todayEnd = new Date() as any;
      endTime.value = todayEnd.setHours(23, 59, 59, 999)
      getNewGoods().then(res => {
        if (res.resultCode == 200) {
          state.goodsList = res.data
        }
      })
    });
    const jumpTo = (url) => {
      Taro.navigateTo({ url: url });
    }
    return { state, jumpTo, endTime, time };
  }
};
</script>
<style lang="scss">
.active-img {
  text-align: center;

  img {
    width: 100%;
    height: 260px;
  }
}

.news-title {
  // width: 90%;
  margin: 20rpx 32rpx 20rpx;
  box-sizing: border-box;
  padding-left: 10rpx;

  span {
    margin-right: 20rpx;
    font-size: 36rpx;
    font-weight: bold;
  }

  .countdown-item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40rpx;
    height: 50rpx;
    background: #FF7F31;
    color: #fff;
    font-size: 26rpx;
    border-radius: 10rpx;
  }

  .more {
    color: #8F9295;
    font-size: 28rpx;
  }
}

.goods-list::-webkit-scrollbar {
  display: none;
}

.goods-list {
  overflow-x: auto;
  // width: 98%;
  margin: 0 32rpx 20rpx;
  white-space: nowrap;
  background: #fff;
  border-radius: 20rpx;
  padding: 20rpx;
  box-sizing: border-box;

  .goods-item {
    display: inline-block;
    width: 40%;
    margin-right: 10rpx;
    height: 320rpx;
    background: url(http://120.92.155.169:9095/uploadPath/2023/10/26/120231026105834.png) no-repeat 0 0;
    background-size: 100% 100%;
    position: relative;
    overflow: hidden;

    .img {
      background: #fff;
      text-align: center;
      height: 250rpx;

      img {
        width: 100%;
        height: 100%;
      }
    }

    .time {
      position: absolute;
      right: 10rpx;
      bottom: 0rpx;
      color: #fff;

      .nut-countdown__content {
        font-size: 20rpx;
      }
    }

    .title {
      text-align: center;
      font-size: 26rpx;
      font-weight: bold;
      word-break: keep-all;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      color: #0B1117;
    }

    .bottom {
      justify-content: center;

      .sell {
        font-size: 24rpx;
        color: #FF5935;

        text {
          color: #CCCCCC;
        }
      }

      .orig {
        color: #CCCCCC;
        margin-left: 15rpx;
        text-decoration: line-through;
        font-size: 24rpx;
      }
    }
  }
}
</style>